/**
 * Created by joy on 03/09/2017.
 */
import BitcoinCashWalletHelper from '../../common/helpers/chain/BitcoinCashWalletHelper'
import fs from 'fs'
import CommonUtil from '../../common/utils/CommonUtil'
import prompt from 'prompt'


export default async () => {
  const bitcoinCashWalletHelper = new BitcoinCashWalletHelper()
  const schema = {
    properties: {
      mnemonic: {
        description: 'Enter your mnemonic',
        type: 'string',
        required: true
      },
      password: {
        description: 'Enter password for mnemonic',
        type: 'string',
        hidden: true,
        replace: '*',
        required: true
      },
      output: {
        description: 'Enter filename to save result',
        type: 'string',
        required: true,
        default: 'temp_data/keys.txt'
      }
    }
  }
  const args = await CommonUtil.getArgsFromConsole(prompt, schema)
  const { mnemonic, password, output } = args
  const result = bitcoinCashWalletHelper.getMasterPairByMnemonic(mnemonic, password)
  CommonUtil.delFileSync(output)
  fs.appendFileSync(output, `mnemonic: "${mnemonic}"` + '\n')
  fs.appendFileSync(output, `password: "${password}"` + '\n')
  for (let [key, value] of Object.entries(result)) {
    fs.appendFileSync(output, `${key}: ${value}` + '\n')
  }
}
